package monster.flight.admin.action.xtgl.dict;

import monster.comm.action.BaseJsonAction;
import monster.comm.log.ILog;
import monster.comm.log.LogService;
import monster.comm.util.ReturnConstant;
import monster.comm.util.SpringApplicationContextFactory;
import monster.flight.admin.manager.service.xtgl.DictService;
import monster.flight.comm.entity.vo.Xt_dict_detail;

/**
 * 
* 创建信息=============
* 类名: monster.flight.admin.action.xtgl.dict.DictDetailCheckAction
* 类作用描述: 验证字典明细的选项编码是否唯一
* 创建人： zhongjianjun
* 创建时间： 2013-1-25 上午11:25:17
* 修改信息1=============
* 修改类型:     //1.修改bug 2.业务变化修改
* 修改描述: 
* 修改人：  
* 修改时间：
 */
public class DictDetailCheckAction extends BaseJsonAction{
	private static final long serialVersionUID = 1L;
	private static ILog log = LogService.getLog(DictDetailCheckAction.class);
	private DictService dictService;
	private Xt_dict_detail dict_detail;
	private String fieldId;
	private String fieldValue;
	 
	public Xt_dict_detail getDict_detail() {
		return dict_detail;
	}
	public void setDict_detail(Xt_dict_detail dict_detail) {
		this.dict_detail = dict_detail;
	}
	public void setFieldId(String fieldId) {
		this.fieldId = fieldId;
	}
	public void setFieldValue(String fieldValue) {
		this.fieldValue = fieldValue;
	}
	
	public void setDictService(DictService dictService) {
		this.dictService = dictService;
	}
	
	public String checkDictDetailOptionId(){
		String islogin = this.isLogin();
		if("0".equals(islogin)){
			returnVO.returnCode=ReturnConstant.IS_NOT_LOGIN;
	    	returnVO.returnDesc="没有登录";
		}
		if("1".equals(islogin)){
			 try {
				 dict_detail.setOption_id(fieldValue);
				 boolean optStatus = dictService.validateOption_idOnly(dict_detail);
				 returnVO.validationReturn = "[\""+fieldId.replaceAll("\\.", "\\\\\\\\.")+"\","+optStatus+"]";
				 returnVO.returnCode=ReturnConstant.IS_DEAL_OK;
				 returnVO.returnDesc="操作成功";
			} catch (Exception e) {
				returnVO.returnCode=ReturnConstant.IS_ERR;
        		returnVO.returnDesc="数据字典明细项的选项编码唯一性验证失败!";
        		log.error(e.getMessage());
			}
		}
		return "success";
	}
	
	public String checkDictDetailForm(){
		String islogin = this.isLogin();
		if(ReturnConstant.IS_NOT_LOGIN.equals(islogin)){
			returnVO.returnCode=ReturnConstant.IS_NOT_LOGIN;
	    	returnVO.returnDesc="没有登录";
		}
		if(ReturnConstant.IS_DEAL_OK.equals(islogin)){
			 try {
				 DictService dictService = (DictService)SpringApplicationContextFactory.getService("dictService");
				 boolean optStatus = dictService.validateOption_idOnly(dict_detail);
				 returnVO.validationReturn = "[[\"dict_detail\\\\.option_id\","+optStatus+",\"ajaxDictDetailCodeCall\"]]";
				 returnVO.returnCode=ReturnConstant.IS_DEAL_OK;
				 returnVO.returnDesc="操作成功";
			} catch (Exception e) {
				returnVO.returnCode=ReturnConstant.IS_ERR;
        		returnVO.returnDesc="数据字典明细中表单验证失败!";
        		log.error(e.getMessage());
			}
		}
		return "success";
	}
}
